package com.real8.romemp.shared;

import com.google.gwt.user.client.Random;

public class GameDataImpl implements GameData {
	private int year;
	private int treasury;
	private int population;

	private int merchantShips;
	private int warShips;
	private int foodReserve;
	private int tradeRate;
	private int foodNeed;
	private int labourArmy;
	private int auxiliaAvailable;
	private int labourArtisans;
	private int labourNavy;
	private int labourMerchants;
	private int labourShipBuilders;
	private int freeLabour;

	private int auxiliaHired;
	private int popularity;

	private boolean shipBuildersEnrolled;

	private int localMerchantShips;
	private int overseeMerchantShips;
	private int localWarShips;
	private int overseeWarShips;
	private int unallocatedShipBuilders;

	@Override
	public void initialize() {
		treasury = 50000;
		year = -55;
		population = 100000;

		// init resources
		initResources();

		// remaining data
		auxiliaHired = 0;
		popularity = 0;
		shipBuildersEnrolled = false;
	}

	private void initResources() {
		merchantShips = Random.nextInt(20) + 111;
		warShips = Random.nextInt(10) + 30;
		foodReserve = Random.nextInt(10) + 10;
		tradeRate = 100;
		foodNeed = population / 1000;
		labourArmy = Random.nextInt(10) + 6;
		auxiliaAvailable = Random.nextInt(6) + 5;
		labourArtisans = Random.nextInt(10) + 11;
		labourNavy = warShips;
		labourMerchants = merchantShips;
		labourShipBuilders = Random.nextInt(30) + 16;
		freeLabour = 250 - labourShipBuilders - labourArtisans
				- labourMerchants - labourNavy - labourArmy;

		if (freeLabour < 0) {
			initResources();
		}
	}

	@Override
	public int getTN_year() {
		return year;
	}

	@Override
	public void setTN_year(int year) {
		this.year = year;
	}

	@Override
	public int getUL_freeLabour() {
		return freeLabour;
	}

	@Override
	public void setUL_freeLabour(int labour) {
		this.freeLabour = labour;
	}

	@Override
	public int getLA_labourArmy() {
		return labourArmy;
	}

	@Override
	public void setLA_labourArmy(int labour) {
		this.labourArmy = labour;
	}

	@Override
	public int getLN_labourNavy() {
		return labourNavy;
	}

	@Override
	public void setLN_labourNavy(int labour) {
		this.labourNavy = labour;
	}

	@Override
	public int getLM_labourMerchants() {
		return labourMerchants;
	}

	@Override
	public void setLM_labourMerchants(int labour) {
		this.labourMerchants = labour;
	}

	@Override
	public int getLE_labourArtisans() {
		return labourArtisans;
	}

	@Override
	public void setLE_labourArtisans(int labour) {
		this.labourArtisans = labour;
	}

	@Override
	public int getLS_labourShipBuilders() {
		return labourShipBuilders;
	}

	@Override
	public void setLS_labourShipBuilders(int labour) {
		this.labourShipBuilders = labour;
	}

	@Override
	public int getMA_auxiliaAvailable() {
		return auxiliaAvailable;
	}

	@Override
	public void setMA_auxiliaAvailable(int auxilia) {
		this.auxiliaAvailable = auxilia;
	}

	@Override
	public int getMH_auxiliaHired() {
		return auxiliaHired;
	}

	@Override
	public void setMH_auxiliaHired(int auxilia) {
		this.auxiliaHired = auxilia;
	}

	@Override
	public int getTR_treasury() {
		return treasury;
	}

	@Override
	public void setTR_treasury(int gold) {
		this.treasury = gold;
	}

	@Override
	public int getPO_population() {
		return population;
	}

	@Override
	public void setPO_population(int population) {
		this.population = population;
	}

	@Override
	public int getUS_unallocatedShipBuilders() {
		return unallocatedShipBuilders;
	}

	@Override
	public void setUS_unallocatedShipBuilders(int shipBuilders) {
		this.unallocatedShipBuilders = shipBuilders;
	}

	@Override
	public boolean getShipBuildersEnrolled() {
		return shipBuildersEnrolled;
	}

	@Override
	public void setShipBuildersEnrolled(boolean enrolled) {
		this.shipBuildersEnrolled = enrolled;
	}

	@Override
	public int getWS_warShips() {
		return warShips;
	}

	@Override
	public void setWS_warShips(int ships) {
		this.warShips = ships;
	}

	@Override
	public int getMS_merchantShips() {
		return merchantShips;
	}

	@Override
	public void setMS_merchantShips(int ships) {
		this.merchantShips = ships;
	}

	@Override
	public int getML_localMerchantShips() {
		return localMerchantShips;
	}

	@Override
	public void setML_localMerchantShips(int ships) {
		this.localMerchantShips = ships;
	}

	@Override
	public int getMO_overseeMerchantShips() {
		return overseeMerchantShips;
	}

	@Override
	public void setMO_overseeMerchantShips(int ships) {
		this.overseeMerchantShips = ships;
	}

	@Override
	public int getWL_localWarShips() {
		return localWarShips;
	}

	@Override
	public void setWL_localWarShips(int ships) {
		this.localWarShips = ships;
	}

	@Override
	public int getWO_overseeWarShips() {
		return overseeWarShips;
	}

	@Override
	public void setWO_overseeWarShips(int ships) {
		this.overseeWarShips = ships;
	}

	@Override
	public int getVL_tradeRate() {
		return tradeRate;
	}

	@Override
	public void setVL_tradeRate(int rate) {
		this.tradeRate = rate;
	}

	@Override
	public int getFS_foodReserve() {
		return foodReserve;
	}

	@Override
	public void setFS_foodReserve(int food) {
		this.foodReserve = food;
	}

	@Override
	public int getFR_foodNeed() {
		return foodNeed;
	}

	@Override
	public void setFR_foodNeed(int food) {
		this.foodNeed = food;
	}

	@Override
	public int getVF_popularity() {
		return popularity;
	}

	@Override
	public void setVF_popularity(int popularity) {
		this.popularity = popularity;
	}

	@Override
	public int getSC_score() {
		int score = (getLA_labourArmy() + getLN_labourNavy()
				+ getLM_labourMerchants() + getLE_labourArtisans() + getLS_labourShipBuilders())
				* 100
				+ getTR_treasury()
				/ 2
				+ (getPO_population() / 50)
				/ (100 - getTN_year());

		return score;
	}
}
